Newer
Older
taehui / taehui-fe / src / app / [language] / commentary / query / usePostCommentary.ts
@Taehui Taehui on 6 Apr 791 bytes 2024-04-07 오전 8:25
import { wwwAPI } from "@/utilities/wwwAPI";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { getMillis } from "taehui-ts/date";

export default function usePostCommentary() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: async ({
      avatarName,
      avatarCipher,
      text,
    }: {
      avatarName: string;
      avatarCipher: string;
      text: string;
    }) => {
      await wwwAPI.post(
        "/commentary",
        {
          avatarName,
          avatarCipher,
          text,
        },
        {
          headers: {
            millis: getMillis(),
          },
        },
      );
    },
    onSuccess: async () => {
      await queryClient.invalidateQueries({ queryKey: ["commentary"] });
    },
  });
}